﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Hosting;
using System.Web.UI.HtmlControls;
using EPiCloner.ResourcesRegistration;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAbstraction;
using EPiServer.PlugIn;

namespace EPiCloner.Templates.Plugins.Cloning
{
    [GuiPlugIn(DisplayName = "EPiCloner.SiteStructureVerification", Description = "Verifies if site structure is alligned with current page type availability rules.", DefaultEnabled = true, Area = PlugInArea.ActionWindow, Url = "/EPiSiteVerification.aspx")]
    public partial class SiteStructureVerificationPlugin : SimplePage
    {
        protected void BtnValidateStructureClicked(object sender, EventArgs e)
        {
            string message = "Root page to verify is a required property!";
            if (!PageReference.IsNullOrEmpty(pageToVerify.PageLink))
            {
                var data = Validator.Validate(pageToVerify.PageLink);
                if (data.Count > 0)
                {
                    rptNotValidItems.DataSource = data;
                    rptNotValidItems.DataBind();
                    message = string.Empty;
                }
                else
                {
                    rptNotValidItems.Visible = false;
                    message = "Structure is valid";
                }
            }

            litResults.Text = message;
        }
    }
}